<template>
  <div>
    <div ref="echarts" style="width: 600px; height: 400px;"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'EChartsComponent',
  data () {
    return {
      myChart: undefined
    }
  },
  mounted () {
    const myChart = echarts.init(this.$refs.echarts)
    myChart.setOption({
      title: {
        text: '柱状图'
      },
      tooltip: {},
      xAxis: {
        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
      },
      yAxis: {},
      series: [
        {
          name: '储量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        }
      ]
    })

    const data = [5, 20, 36, 10, 10, 20];
    function run () {
      for (var i = 0; i < data.length; ++i) {
        if (Math.random() > 0.9) {
          data[i] += Math.round(Math.random() * 2000);
        } else {
          data[i] += Math.round(Math.random() * 200);
        }
      }
      myChart.setOption({
        series: [
          {
            type: 'bar',
            data
          }
        ]
      });
    }
    setInterval(function () {
      run();
    }, 3000);
  },
  methods: {
  }
}
</script>
<style lang="scss" scoped></style>
